import { Column, Entity, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Profile } from './profile.entity';
import { Logs } from '../logs/logs.entity';
import { Roles } from '../roles/roles.entity';
import { Exclude } from 'class-transformer';

@Entity()
export class User {
    @PrimaryGeneratedColumn()
    @Exclude()
    id: number;

    @Column({ unique: true })
    username: string;

    @Column()
    @Exclude()
    password: string;

    @Column()
    avatar: string;

    @Column()
    nickname: string;

    @Column()
    active: number;

    @OneToMany(() => Logs, (logs) => logs.user)
    logs: Logs[];

    @ManyToMany(() => Roles, (roles) => roles.users, { cascade: ['insert'] })
    @JoinTable({ name: 'user_roles' })
    roles: Roles[];

    @OneToOne(() => Profile, (profile) => profile.user, { cascade: true })
    profile: Profile;

    // @AfterInsert()
    // AfterInsert(){
    //   console.log('AfterInsert');

    // }

    // @AfterRemove()
    // AfterRemove(){
    //   console.log('AfterRemove');

    // }
}
